/**
 * 车辆信息初始化
 */
var ReportTemplate = {
    id: "ReportTemplateTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};


ReportTemplate.showErrInfo = function(){
	Feng.error("文件不存在!");
}
/**
 * 初始化表格的列
 */
ReportTemplate.initColumn = function () {
    return [
        {field: 'selectItem', checkbox: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reportType', field: 'reportType', align: 'center', valign: 'middle', sortable: true},
        {title: 'reportContent', field: 'reportContent', align: 'center', valign: 'middle', sortable: true},
        {title: 'modeCondition', field: 'modeCondition', align: 'center', valign: 'middle', sortable: true},
        {title: 'modeContent', field: 'modeContent', align: 'center', valign: 'middle', sortable: true}];
};
/**
 * 检查是否选中
 */
ReportTemplate.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        ReportTemplate.seItem = selected;
        return true;
    }
};

ReportTemplate.singleCheck = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
    	if(selected.length > 1){
    		Feng.info("请选择表格中的一条记录进行操作！");
            return false;
    	}else{
    		ReportTemplate.seItem = selected[0];
            return true;
    	}
        
    }
};






/**
 * 删除
 */
ReportTemplate.delete = function () {
	
	if (this.check()) {

    	var selectedItems = ReportTemplate.seItem;
    	
    	var ids = "";
    	var names = "";
    	for(var i=0;i<selectedItems.length;i++){
    		var selectedItem = selectedItems[i];
    		if(i<selectedItems.length - 1){
    			ids = ids+selectedItem.id + "," ;    			
    		}else{
    			ids = ids+selectedItem.id;   		
    		}
    	}
    	
        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/base/reportTemplate/save/delete", function (data) {
            	if(data.resultCode==0){
            		Feng.success("删除成功!");
                    Parts.table.refresh();
            	}else{
            		Feng.error(data.msg + "!");
            	}
                
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("ids", ids);
            ajax.start();
        };

        Feng.confirm("是否刪除选中的字典?", operation);
        
        ReportTemplate.table.refresh();
        
    }
	
	
};


ReportTemplate.add = function () {
    var index = layer.open({
        type: 2,
        title: '添加字典',
        area: ['800px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/base/reportTemplate/add/'
    });
    this.layerIndex = index;
};

ReportTemplate.view = function(){
	 if (this.singleCheck()) {

		 var index = layer.open({
		        type: 2,
		        title: '添加字典',
		        area: ['800px', '500px'], //宽高
		        fix: false, //不固定
		        maxmin: true,
		        content: Feng.ctxPath + '/base/reportTemplate/view/'+ this.seItem.id
		    });
		    this.layerIndex = index;
	        
	       
	 }
};



ReportTemplate.edit = function () {
	if(this.singleCheck()){
    var index = layer.open({
        type: 2,
        title: '添加字典',
        area: ['800px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/base/reportTemplate/edit/'+ this.seItem.id
        													  
    });
    this.layerIndex = index;
	}
};




/**
 * 重置
 */
ReportTemplate.resetSearch = function () {
    $("#condition").val("");
    ReportTemplate.table.refresh();
};

/**
 * 查询字典列表
 */
ReportTemplate.search = function () {
	var queryData = {};
    
    //reportTemplate.table.refreshOptions({pageNumber:1});
    ReportTemplate.table.refresh({query: queryData});
};

$(function () {
	ReportTemplate.init(); 
	
	
});

ReportTemplate.init = function(){
	var defaultColunms = ReportTemplate.initColumn();
	var paramsId =[
		];
    var table = new BSTable(ReportTemplate.id, "/base/reportTemplate/list", defaultColunms);
    table.setPaginationType("server");
     table.init();
     ReportTemplate.table =table;
}

ReportTemplate.close = function () {
    parent.layer.close(window.parent.ReportTemplate.layerIndex);
};


